from django.http import StreamingHttpResponse
from django.http import HttpResponse
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def big_file_download(request):
    # do something...
    def file_iterator(file_name, chunk_size=512):
        with open(file_name) as f:
            while True:
                c = f.read(chunk_size)
                if c:
                    yield c
                else:
                    break

    the_file_name = request.GET['filename']
    the_file_path =os.path.join(BASE_DIR,"upload", the_file_name);
    if os.path.exists(the_file_path):
        response = StreamingHttpResponse(file_iterator(the_file_path))
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name.encode("utf-8"))
        return response
    else:
        return HttpResponse("file is not exist!")
